package main

import (
	"crypto/md5"
	"crypto/sha512"
	"encoding/hex"
	"fmt"
	"github.com/anaskhan96/go-password-encoder"
	"io"
	"strings"
)

func genMd5(code string)string{
	Md5:=md5.New()
	_,_=io.WriteString(Md5,code)
	return hex.EncodeToString(Md5.Sum(nil))
}
func main() {
	//dsn:="root:root@tcp(127.0.0.1:3306)/mxshop_user_srv?charset=utf8mb4&parseTime=true&loc=Local"
	//newLogger:=logger.New(
	//	log.New(os.Stdout,"\r\n",log.LstdFlags),
	//	logger.Config{
	//		SlowThreshold: time.Second,
	//		LogLevel:logger.Info,
	//		Colorful: true,
	//	},
	//	)
	//db,err:=gorm.Open(mysql.Open(dsn),&gorm.Config{
	//	NamingStrategy: schema.NamingStrategy{
	//		SingularTable: true,
	//	},
	//	Logger: newLogger,
	//})
	//if err!=nil{
	//	panic(err)
	//}
	//_=db.AutoMigrate(&model.User{})
	//fmt.Println(genMd5("12345"))
	//fmt.Println(genMd5("12345"))


	// Using the default options
	//salt, encodedPwd := password.Encode("generic password", nil)
	//check := password.Verify("generic password", salt, encodedPwd, nil)
	//fmt.Println(check) // true

	// Using custom options
	options := &password.Options{16, 100, 32, sha512.New}
	salt, encodedPwd := password.Encode("generic password", options)
	fmt.Println(salt) // true
	fmt.Println(encodedPwd) // true
	newPassword:=fmt.Sprintf("$pdfdf2-sha512$%s$%s",salt,encodedPwd)
	fmt.Println(len(newPassword)) // true
	passwordInfo:=strings.Split(newPassword,"$")
	fmt.Println(passwordInfo) // true
	check := password.Verify("generic password", passwordInfo[2], passwordInfo[3], options)
	fmt.Println(check) // true

}
